/* Copyright (c) [2024] [ylc]. Licensed under Apache-2.0 License. */
#ifndef __TM1628_H
#define __TM1628_H

#include "my_define.h"

typedef enum{
    TM_DISPLAY_MODE_4_13        = 0x00U,  
    TM_DISPLAY_MODE_5_12        = 0x01U, 
    TM_DISPLAY_MODE_6_11        = 0x02U, 
    TM_DISPLAY_MODE_7_10        = 0x03U, 
}TM_DISPLAY_MODE_CMDTypeDef;

typedef enum{
    TM_DATA_WRITE_INC           = 0x40U,  
    TM_DATA_READ_INC            = 0x42U, 
    TM_DATA_WRITE_FIXED         = 0x44U, 
    TM_DATA_READ_FIXED          = 0x46U, 
}TM_DATA_CMDTypeDef;

typedef enum{
    TM_DISPLAY_CTRL_OFF         = 0x80U,  
    TM_DISPLAY_CTRL_ON          = 0x81U, 
    TM_DISPLAY_CTRL_1_16        = 0x88U, 
    TM_DISPLAY_CTRL_2_16        = 0x89U, 
    TM_DISPLAY_CTRL_4_16        = 0x8AU, 
    TM_DISPLAY_CTRL_10_16       = 0x8BU, 
    TM_DISPLAY_CTRL_11_16       = 0x8CU, 
    TM_DISPLAY_CTRL_12_16       = 0x8DU, 
    TM_DISPLAY_CTRL_13_16       = 0x8EU, 
    TM_DISPLAY_CTRL_14_16       = 0x8FU, 
}TM_DISPLAY_CTRL_CMDTypeDef;

typedef enum{
    TM_ADDRESS_C0        = 0xC0U,  
    TM_ADDRESS_C1        = 0xC1U, 
    TM_ADDRESS_C2        = 0xC2U, 
    TM_ADDRESS_C3        = 0xC3U, 
    TM_ADDRESS_C4        = 0xC4U,  
    TM_ADDRESS_C5        = 0xC5U, 
    TM_ADDRESS_C6        = 0xC6U, 
    TM_ADDRESS_C7        = 0xC7U, 
    TM_ADDRESS_C8        = 0xC8U,  
    TM_ADDRESS_C9        = 0xC9U, 
    TM_ADDRESS_CA        = 0xCAU, 
    TM_ADDRESS_CB        = 0xCBU, 
    TM_ADDRESS_CC        = 0xCCU,  
    TM_ADDRESS_CD        = 0xCDU, 
}TM_ADDRESS_CMDTypeDef;


typedef union{
	struct{
		//com1
		u8 G1:1;
		u8 F1:1;
		u8 E1:1;
		u8 D1:1;
		u8 C1:1;
		u8 B1:1;
		u8 A1:1;
		u8 H1:1;
		
		//com2
		u8 G2:1;
		u8 F2:1;
		u8 E2:1;
		u8 D2:1;
		u8 C2:1;
		u8 B2:1;
		u8 A2:1;
		u8 H2:1;
		
		//com3
		u8 G3:1;
		u8 F3:1;
		u8 E3:1;
		u8 D3:1;
		u8 C3:1;
		u8 B3:1;
		u8 A3:1;
		u8 H3:1;
		
		//com4
		u8 G4:1;
		u8 F4:1;
		u8 E4:1;
		u8 D4:1;
		u8 C4:1;
		u8 B4:1;
		u8 A4:1;
		u8 H4:1;
		
		//com5
		u8 G5:1;
		u8 F5:1;
		u8 E5:1;
		u8 D5:1;
		u8 C5:1;
		u8 B5:1;
		u8 A5:1;
		u8 H5:1;
		
		//com6
		u8 G6:1;
		u8 F6:1;
		u8 E6:1;
		u8 D6:1;
		u8 C6:1;
		u8 B6:1;
		u8 A6:1;
		u8 H6:1;
		
		//com7
		u8 G7:1;
		u8 F7:1;
		u8 E7:1;
		u8 D7:1;
		u8 C7:1;
		u8 B7:1;
		u8 A7:1;
		u8 H7:1;
		
		//com8
		u8 G8:1;
		u8 F8:1;
		u8 E8:1;
		u8 D8:1;
		u8 C8:1;
		u8 B8:1;
		u8 A8:1;
		u8 H8:1;

        //com9
		u8 G9:1;
		u8 L6:1;
		u8 L5:1;
		u8 L4:1;
		u8 L3:1;
		u8 L2:1;
		u8 L1:1;
		u8 H9:1;

        //com10
		u8 G10:1;
		u8 F10:1;
		u8 E10:1;
		u8 D10:1;
		u8 C10:1;
		u8 B10:1;
		u8 A10:1;
		u8 H10:1;

        //com11
		u8 G11:1;
		u8 F11:1;
		u8 L10:1;
		u8 L11:1;
		u8 L9:1;
		u8 L8:1;
		u8 L7:1;
		u8 H11:1;

        //com12
		u8 G12:1;
		u8 F12:1;
		u8 E12:1;
		u8 D12:1;
		u8 C12:1;
		u8 B12:1;
		u8 A12:1;
		u8 H12:1;

        //com13
		u8 G13:1;
		u8 F13:1;
		u8 E13:1;
		u8 D13:1;
		u8 C13:1;
		u8 B13:1;
		u8 A13:1;
		u8 H13:1;

        //com14
		u8 G14:1;
		u8 F14:1;
		u8 E14:1;
		u8 D14:1;
		u8 C14:1;
		u8 B14:1;
		u8 A14:1;
		u8 H14:1;
	}led;
	struct{			//段码映射
		u8 G:1;
		u8 F:1;
		u8 E:1;
		u8 D:1;
		u8 C:1;
		u8 B:1;
		u8 A:1;
		u8 H:1;
	}b[14];
	u8 buf[14];
}DIS_SEG_T;

typedef struct{
    u8 key[5];
    DIS_SEG_T reg;
	void (*InitPort)(void);	
	void (*DelayUs)(void);	  
	void (*DIO_H)(void);      	
	void (*DIO_L)(void);       
	void (*CLK_H)(void);      	
	void (*CLK_L)(void);      
	void (*STB_H)(void);      	
	void (*STB_L)(void);    
	u8   (*READ_DIO)(void);     
	u8   (*READ_CLK)(void);   
}mTMTypedef_t;
extern mTMTypedef_t Tm1;

void tm1628_init(void);
void tm1628_clear(void);
void tm1628_full_display(void);
void tm1628_refresh(void);
void tm1628_read_key(void);
void tm_SendCmd(mTMTypedef_t* tm, u8 cmd) ;

#endif